#include<iostream>
#include<algorithm>

using namespace std;

const int N = 2510;
struct node
{
	int l;
	int r;
}a[N];

struct bott
{
	int kind;
	int num;

}b[N];

int c, l;

bool cmp1(node& x1, node& x2)
{
	return x1.l > x2.l;
}

bool cmp2(bott& y1, bott& y2)
{
	return y1.kind > y2.kind;
}

int main()
{
	cin >> c >> l;
	for (int i = 1; i <= c; i++)
	{
		int x, y; cin >> x >> y;
		a[i].l = x; a[i].r = y;
	}

	sort(a + 1, a + 1 + c, cmp1);

	for (int i = 1; i <= l; i++)
	{
		int kind, num; cin >> kind >> num;
		b[i].kind = kind; b[i].num = num;
	}

	sort(b + 1, b + 1 + l, cmp2);

     int ret = 0;
	for (int i = 1; i <= c; i++)
	{
		for (int j = 1; j <= l; j++)
		{
			if (b[j].num == 0) continue;
			if (a[i].l > b[j].kind) break;
			if (a[i].r < b[j].kind) continue;

				b[j].num--; ret++; break;
		}
	}

    cout << ret;
	return 0;
}

